package com.character.controller;

import com.character.entity.*;
import com.character.service.ResultService;
import com.character.service.ResultVoService;
import com.character.service.TesterService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

import java.util.*;

/**
 * (Result)表控制层
 *
 * @author makejava
 * @since 2021-11-28 19:47:25
 */
@RestController
@RequestMapping("result")
public class ResultController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ResultVoService resultVoService;
    @Resource
    private ResultService resultService;
    @Resource
    private TesterService testerService;
    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("selectAll")
    public MyReturn selectAll(Long page  ,Long limit,Tester tester) {
        List<ResultVo> testers = resultVoService.queryAll(page,limit,tester);
        return super.success(testers,resultVoService.getCount(tester));
    }

    /**
     * 删除数据
     *
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public MyReturn deleteByMap(@RequestParam("idList[]") List<Long> idList) {
        Map map=new HashMap();

        System.out.println(idList);
        boolean deleteTester =testerService.removeByIds(idList);
        for (Long testId : idList){
            map.put("tester_id",testId);
            boolean deleteByMap = resultService.removeByMap(map);
        }
        if (deleteTester) {
            return super.success(null);
        } else {
            return super.failed(null);
        }
    }
    /**
     *
     * @param resultList
     * @return com.character.entity.MyReturn
     * @author 高冷
     * @description:批量插入测试结果,前台传入结果对象集合
     * @date 2021/12/3 9:22
     */
    @RequestMapping("insert")
    public MyReturn insert(@RequestBody List<Result> resultList){
        boolean saveBatch = this.resultService.saveBatch(resultList);
        if(saveBatch){
            return  super.success(null);
        }else {
            return  super.failed(null);
        }
    }
}

